<template>
  <div class="big">
        <div>
            <ul class="nav">
                <li>商品
                    <span></span>
                </li>
                <li>评价
                    <span></span>
                </li>
                <li>详情
                    <span></span>
                </li>
                <li>推荐
                    <span></span>
                </li>
            </ul>
        </div>
        <div class="mid">
            <div class="mid1">
                <img :src="$pre+detail.img" alt="">
            </div>
            <div class="mid2">
                <div class="top">
                    <div class="zuo">
                        <p><span v-if="detail.price">￥{{detail.price|filterPrice}}</span><span>￥1099 </span></p>
                    </div>
                    <div class="you">
                        <img :src="require('../../assets/img/商品详情 (2).png')" alt="">
                        <p>收藏</p>
                    </div>
                </div>
                <div class="xia">
                    <p>{{detail.goodsname}}</p>
                    <div v-html="detail.description"></div>
                    <h3>规格：{{detail.specsname}}</h3>
                    <button v-for="item in detail.specsattr" :key="item">{{item}}</button>
                    <p>11.11限时299元起</p>
                    <div>
                        <span>此商品于2020-11-11,00点结束闪购特卖，品牌美妆闪购专场</span>
                        <span>查看></span>
                    </div>
                </div>
            </div>
            <div class="mid3">
                <div class="shang">
                    <div class="left">领劵</div>
                    <div class="right">
                        <img :src="require('../../assets/img/商品详情 (4).png')" alt="">
                        <img :src="require('../../assets/img/商品详情 (5).png')" alt="">
                        <img :src="require('../../assets/img/商品详情 (6).png')" alt="">
                    </div>
                </div>
                <div class="xia">
                    <div class="left">分期</div>
                    <div class="right">
                        <p>可选3/6/12期</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="buttom">
            <div>
                <img :src="require('../../assets/img/商品详情 (8).png')" alt="">
                <p>客服</p>
            </div>
            <div>
                <img :src="require('../../assets/img/商品详情 (8).png')" alt="">
                <p>店铺</p>
            </div>
            <div>
                <img :src="require('../../assets/img/商品详情 (9).png')" alt="">
                <p>购物车</p>
            </div>
            <button  @click="add" class="btn1">加入购物车</button>
            <button class="btn2">立即购买</button>
        </div>
    </div>
</template>

<script>
import {Toast} from "vant"
import {reqAdd,reqDetail} from "../../http/api"
export default {
  data(){
    return{
      //初始值
      detail:{}
    };
  },
  mounted() {
    console.log("detail 挂载完成，开始请数据");
    console.log(this.$route.params.id);
    // ajax
    reqDetail({
        id: this.$route.params.id,
      }).then((res) => {
      
      this.detail=res.data.list[0]
      this.detail.specsattr=this.detail.specsattr.split(",")
      console.log(this.detail);
    });
  },
  methods:{
    //加入购物车
    add(){
      reqAdd({
        uid:JSON.parse(localStorage.getItem("user")).uid,
        goodsid:this.detail.id,
        num:1
      }).then(res=>{
        if(res.data.code==200){
          Toast(res.data.msg)
        }
      })
    }
  }
}
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
}
.big {
  max-width: 7.5rem;
  overflow: hidden;
}
.nav {
  height: 0.76rem;
  background: linear-gradient(to bottom, #ff7864 40%, #ff887c 60%);
  color: white;
  font-size: 0.28rem;
  display: flex;
  justify-content: space-around;
  line-height: 0.74rem;
}
.nav li:nth-of-type(1) {
  font-size: 0.32rem;
}
.nav span {
  display: block;
  width: 0.44rem;
  height: 2px;
  background: white;
  margin: 0 auto;
  display: none;
}
.nav li:hover span {
  display: block;
}
.mid {
  background: white;
}
.mid .mid1 img {
  height: 7.5rem;
}
.mid2 {
  height: 2.92rem;
  width: 7.14rem;
  margin: 0 auto;
  background: white;
}
.mid2 .top {
  display: flex;
  justify-content: space-between;
}
.mid2 .top .zuo p {
  color: red;
  font-size: 0.5rem;
  line-height: 0.4rem;
  font-weight: 900;
  line-height: 0.74rem;
}
.mid2 .top .zuo p span:nth-of-type(1) {
  color: red;
  font-size: 0.60rem;
}
.mid2 .top .zuo p span:nth-of-type(2) {
  color: #989898;
  font-size: 0.25rem;
  text-decoration: line-through;
  font-weight: 900;
}
.mid2 .top .you img {
  width: 0.22rem;
  height: 0.21rem;
  margin-top: 0.2rem;
}
.mid2 .top .you p {
  color: red;
  font-size: 0.22rem;
  line-height: 0.35rem;
}
.mid2 .xia p:nth-of-type(1) {
  font-size: 0.36rem;
  line-height: 0.4rem;
}
.mid2 .xia p:nth-of-type(2) {
  font-size: 0.28rem;
  color: #999999;
  line-height: 0.42rem;
}
.mid2 .xia p:nth-of-type(3) {
  width: 1.66rem;
  height: 0.37rem;
  background: #ff8066;
  color: white;
  font-size: 0.22rem;
  text-align: center;
  line-height: 0.37rem;
  margin-top: 0.18rem;
  margin-bottom: 0.18rem;
}
.mid2 .xia div {
  width: 7.14rem;
  height: 0.38rem;
  background: #f2f2f2;
  display: flex;
  justify-content: space-between;
}
.mid2 .xia div span:nth-of-type(1) {
  font-size: 0.22rem;
  line-height: 0.38rem;
  color: #c2c2c2;
}
.mid2 .xia div span:nth-of-type(2) {
  font-size: 0.22rem;
  color: red;
  line-height: 0.38rem;
}
.mid3 {
  height: 2rem;
  background: #f2f2f2;
  width: 100%;
  overflow: hidden;
}
.mid3 .shang {
  display: flex;
  justify-content: space-between;
  background: white;
  height: 0.9rem;
  margin-top: 0.2rem;
  width: 100%;
}
.mid3 .shang .left {
  font-size: 0.26rem;
  font-weight: 900;
  margin-top: 0.4rem;
  margin-left: 0.2rem;
}
.mid3 .shang .right {
  width: 6.24rem;
  height: 0.9rem;
  border-bottom: 2px solid #e6e6e6;
}
.mid3 .shang .right {
  display: flex;
  justify-content: flex-start;
}
.mid3 .shang .right img {
  width: 0.78rem;
  height: 0.32rem;
  margin-top: 0.4rem;
}
.mid3 .shang .right img:nth-of-type(1),
img:nth-of-type(2) {
  margin-right: 0.2rem;
}
.mid3 .xia {
  display: flex;
  justify-content: space-between;
  background: white;
  height: 0.86rem;
  width: 100%;
  border-bottom: 2px solid #e6e6e6;
}
.mid3 .xia .left {
  font-size: 0.26rem;
  font-weight: 900;
  margin-top: 0.4rem;
  margin-left: 0.2rem;
}
.mid3 .xia .right {
  width: 6.24rem;
  height: 0.66rem;
}
.mid3 .xia .right {
  display: flex;
  justify-content: flex-start;
}
.mid3 .xia .right p {
  color: #adaaaa;
  margin-top: 0.4rem;
}
.buttom {
  height: 0.98rem;
  display: flex;
  justify-content: space-between;
}
.buttom div img:nth-of-type(1) {
  margin-left: 0.42rem;
}
.buttom div img {
  width: 0.4rem;
  height: 0.4rem;
  margin-top: 0.13rem;
  margin-bottom: 0.12rem;
}
.buttom div p {
  font-size: 0.22rem;
  color: #948f8f;
  text-indent: 0.42rem;
}
.buttom div:nth-of-type(3) p {
  text-indent: 0.3rem;
}
.buttom div {
  flex-grow: 1;
}
.btn1 {
  width: 2.2rem;
  height: 0.98rem;
  background: #ffcc66;
  font-size: 0.32rem;
  color: #663014;
  line-height: 0.98rem;
  text-align: center;
  border: 0;
  flex-grow: 0;
}
.btn2 {
  width: 2.2rem;
  height: 0.98rem;
  background: #ff6040;
  font-size: 0.32rem;
  color: white;
  line-height: 0.98rem;
  text-align: center;
  border: 0;
  flex-grow: 0;
}

</style>